package cn.edu.zut.cs.service.impl;

import cn.edu.zut.cs.pojo.Equipment;
import cn.edu.zut.cs.pojo.User;
import cn.edu.zut.cs.mapper.UserMapper;
import cn.edu.zut.cs.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户管理 服务实现类
 * </p>
 *
 * @author user
 * @since 2021-06-16
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Resource
    private UserMapper userMapper;
    @Resource
    private UserService userService;

    //根据id查询管理员
    @Override
    public User selectUserById(Integer userid) {
        User user = userMapper.selectById(userid);
        return user;
    }

    @Override
    public void updateUserById(User user) {

        userMapper.updateById(user);
    }


    //查找某公司的所有员工
    @Override
    public List<User> searchAllStaff(User user) {
        if(user.getUserlevel()==1){
            QueryWrapper<User> wrapper=new QueryWrapper<>();
            wrapper.eq("usercompany",user.getUsercompany()).eq("userlevel",2);
            List<User> list = userService.list(wrapper);
            return list;
        }else{
            return null;
        }
    }

    //查找某公司名下某仓库的所有员工
    @Override
    public List<User> searchStaffByLocation(User user,String location) {
        if(user.getUserlevel()==1){
            QueryWrapper<User> wrapper=new QueryWrapper<>();
            wrapper.eq("usercompany",user.getUsercompany()).eq("userlevel",2).eq("userlocation",location);
            List<User> list = userService.list(wrapper);
            return list;
        }else{
            return null;
        }
    }
}
